
#include <stdio.h>
#include <BFile>
#include <BGlyph>

#include "ReadWrite_svg.h"

ReadWrite_svg::ReadWrite_svg()
{
	_author = "zym";
	_version = "1.0";
	_description = "This is BWE Plugin for reading *.bmp image file, write width libjpeg, thank a lot !";
}
ReadWrite_svg::~ReadWrite_svg()
{

}

void ReadWrite_svg::setOptions(const BString& options)
{
	_options = options;
}
const BString& ReadWrite_svg::options() const
{
	return _options;
}

const BString& ReadWrite_svg::author() const
{
	return _author;
}
const BString& ReadWrite_svg::version() const
{
	return _version;
}
const BString& ReadWrite_svg::description() const
{
	return _description;
}
const BString& ReadWrite_svg::message() const
{
	return _message;
}

BObject* ReadWrite_svg::load(const BString& fileName)
{
	_document.load(fileName);
	BXmlNode* svgNode = _document.node("svg");
	if (!svgNode)
		return 0;

	BGlyph* graphic = new BGlyph();
	graphic->setNode(svgNode);

	BString name = fileName.name();
	name.remove(name.find('.'), name.size());
	graphic->setName(name);
	return graphic;
}
bool ReadWrite_svg::load(const BString& fileName, BObject* object)
{
	_document.load(fileName);
	BXmlNode* svgNode = _document.node("svg");
	if (!svgNode)
		return false;

	BGlyph* graphic = dynamic_cast<BGlyph*>(object);
	if (!graphic)
		return false;

	graphic->setNode(svgNode);

	BString name = fileName.name();
	name.remove(name.find('.'), name.size());
	graphic->setName(name);

	return true;
}
bool ReadWrite_svg::save(const BString& fileName, const BObject* object) const
{
	int interval = 0;
	const int svg_width = 0;
	const int svg_height = 0;
	BList<BImage> svg_list;
	const BImage* image = dynamic_cast<const BImage*>(object);
	if (!image)
		return false;


	return true;
}

BObject* ReadWrite_svg::read(const BBuffer& buffer)
{
	BXmlNode* node = _document.read(buffer);
	if (!node)
		return 0;

	BGlyph* graphic = new BGlyph();
	graphic->setNode(node);

	return graphic;
}
bool ReadWrite_svg::read(const BBuffer& buffer, BObject* object)
{
	BImage* image = dynamic_cast<BImage*>(object);
	if (!image)
		return false;

	return true;
}
bool ReadWrite_svg::write(BBuffer& buffer, const BObject* object) const
{
	const BImage* image = dynamic_cast<const BImage*>(object);
	if (!image)
		return false;

	Format format = image->format();
	const BByteArray* pixels = image->pixels();
	int pixelSize = image->width() * image->height();
	return true;
}
